﻿using OASystem.BLL.IService;
using OASystem.BLL.Service;
using OASystem.Model;
using OASystem.Models;
using OASystem.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;

namespace OASystem.Controllers
{
    public class PartController : Controller
    {
        public static Departinfo user;
        private IPartService partService;
    
        public static ResponseResult departinfos1;
        public static ResponseResult departinfos2;

        public PartController(IPartService _partService)
        {
            partService = _partService;
        }
        /// <summary>
        /// 添加部门信息
        /// </summary>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public JsonResult PartAdd(Departinfo departinfo)
        {
            Operate operate = new Operate();
            operate.Success = partService.Add(departinfo);
            ViewBag.User = departinfo;
            return Json(operate);
        }
        /// <summary>
        /// 删除部门信息
        /// </summary>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public JsonResult PartDelect(Departinfo departinfo)
        {
            Operate operate = new Operate();
            operate.Success = partService.Delete(departinfo);
            return Json(operate);
        }
        /// <summary>
        /// 显示编辑数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult Update(int id)
        {
            ResponseResult responseResult = new ResponseResult();
            PartService service = new PartService();
            responseResult = service.Update(id);
            user = responseResult.data as Departinfo;
            return Json(responseResult);
        }
        /// <summary>
        /// 修改用户信息
        /// </summary>
        /// <param name="function"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult UpdateDepart(Departinfo departinfo)
        {
            Operate operate = new Operate();
            operate.Success = partService.Update(departinfo);
            return Json(operate);
        }
        /// <summary>
        /// 删除用户信息
        /// </summary>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public JsonResult DelectDepart(Departinfo departinfo)
        {
            Operate operate = new Operate();
            operate.Success = partService.Delete(departinfo);
            return Json(operate);
        }
        /// <summary>
        /// 查询集合
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
      public JsonResult QueryDepart(string username)
        {
            PartService partServices = new PartService();
            departinfos1 = partServices.QueryDepart(username);
            Expression<Func<Departinfo, bool>> lambdaExpression = a => true;
            if (username=="")
            {
                departinfos1.data = partServices.QueryList(lambdaExpression);
            }
            return Json(departinfos1);
        }
        /// <summary>
        /// 判断
        /// </summary>
        /// <param name="maillist"></param>
        /// <returns></returns>
        public JsonResult QueryPart(string name)
        {
            //操作对象
            ResponseResult result = new ResponseResult();
            Part_tailService service = new Part_tailService();
            result.data = service.QueryDepart(name);
            return Json(result.data);
        }
    }
}